package com.tao.utilslib.log.logsave.task;

import com.tao.utils.TimeSimpleUtil;
import com.tao.utilslib.data.Obj;

import java.io.OutputStream;
import java.io.Writer;

public abstract class BaseAddTask implements ILogTask {
    public String appendLogHead(String logStr) {
        System.err.println(logStr);
        StringBuilder sb = new StringBuilder();
        String s = "";
        try {
            s = TimeSimpleUtil.TimeNowWithFormat();
        } catch (Exception e) {
            e.printStackTrace();
        }
        sb.append(s);
        sb.append(" >>> ");
        sb.append("\n");

        sb.append(logStr);
        return sb.toString();
    }


    public void closeIo(Object out) {
        if (Obj.isNULL(out)) return;
        
        try {
            if (out instanceof OutputStream) {
                ((OutputStream) out).close();
            } else if (out instanceof Writer) {
                ((Writer) out).close();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
